package com.example.zg6.splash;

import android.content.Intent;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.Observer;
import androidx.viewbinding.ViewBinding;

import com.blankj.utilcode.util.ToastUtils;
import com.example.common.filed.DataActionEntity;
import com.example.common.mlivedata.LiveDataBus;
import com.example.common.mvvm.view.BaseActivity;
import com.example.zg6.databinding.ActivitySplashBinding;
import com.example.zg6.fragment.FrameActivity;

import java.util.Map;

import tv.danmaku.ijk.media.player.IjkMediaPlayer;

public class SplashActivity extends BaseActivity<ActivitySplashBinding, SplashViewModel> {

    private Observer<DataActionEntity> observer;

    @Override
    public View bindLayout() {
        return v.getRoot();
    }

    @Override
    public ViewBinding initBind() {
        return ActivitySplashBinding.inflate(inflater);
    }

    @Override
    public void initView() {


    }

    @Override
    public void initData() {
        observer = new Observer<DataActionEntity>() {
            @Override
            public void onChanged(DataActionEntity dataActionEntity) {
                if (dataActionEntity.action.equals("DOWNTIME")) {
                    String time = (String) dataActionEntity.data.get("time");
                    v.splashTimeTv.setText(time);
                    if (time.equals("0s")) {
                        startActivity(new Intent(SplashActivity.this, FrameActivity.class));
                    }
                }

            }
        };

        vm.vmData.uiData.observe(this, observer);

    }

    @Override
    protected String pageName() {
        return "启屏页";
    }

    @Override
    public void receiveData(Map<String, Object> data) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        vm.vmData.uiData.removeObserver(observer);
    }
}
